<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <h5>您的余额还有
        <span id="amount">$$$amount$$$</span>
    </h5>
    <button id="button">打钱</button>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        button.addEventListener('click',(e)=>{
            $.ajax({                          //这是不是Ajax，一个动态的script
                url: "http://jack:8002/pay",     //告诉url
                dataType: "jsonp",              //告诉使用JSONP
                success: function (response) {   //告诉成功后要做什么
                    if (response === 'success') {
                        amount.innerText = amount.innerText - 1
                    }
                }
            })
        })
          
            
            
        // let script = document.createElement('scripy')
        // let functionName = 'frank' + parseInt(Math.random() * 10000, 10)
        // window.functionName = function (result) {
        //     if (result === 'success') {
        //         amount.innerText = amount.innerText - 1
        //     } else {

        //     }
        // }
        // script.src = 'http://jack.com:8002/pay?callback=' + functionName
        // document.body.appendChild(script)
        // script.onload = function (e) {
        //     e.currentTarget.remove()
        //     delete window[functionName]
        // }
        // script.onerror = function () {
        //     alert('fail')
        //     e.currentTarget.remove()
        //     delete window[functionName]
        // }
    </script>
</body>

</html>